<!DOCTYPE html>
<html>
<head><meta name="generator" content="Hexo 3.8.0">
  <meta charset="utf-8">
  

  
  <title>linux platform bus 总线分析 | 章军的博客</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <meta name="description" content="1. Linux 平台总线的简介 (platform bus)    关于平台总线我把 linux kernel 下的文档翻译了一遍 ，英文原版地址为 https://github.com/torvalds/linux/blob/master/ Documentation/driver-api/driver-model/platform.rst , 翻译后的地址为 https://github.c">
<meta name="keywords" content="platform bus,linux driver">
<meta property="og:type" content="article">
<meta property="og:title" content="linux platform bus 总线分析">
<meta property="og:url" content="http://octopuscloud.top/2019/10/19/linux-platform-bus-总线分析/index.html">
<meta property="og:site_name" content="章军的博客">
<meta property="og:description" content="1. Linux 平台总线的简介 (platform bus)    关于平台总线我把 linux kernel 下的文档翻译了一遍 ，英文原版地址为 https://github.com/torvalds/linux/blob/master/ Documentation/driver-api/driver-model/platform.rst , 翻译后的地址为 https://github.c">
<meta property="og:locale" content="China">
<meta property="og:updated_time" content="2019-11-17T08:54:35.156Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="linux platform bus 总线分析">
<meta name="twitter:description" content="1. Linux 平台总线的简介 (platform bus)    关于平台总线我把 linux kernel 下的文档翻译了一遍 ，英文原版地址为 https://github.com/torvalds/linux/blob/master/ Documentation/driver-api/driver-model/platform.rst , 翻译后的地址为 https://github.c">
  
    <link rel="alternate" href="/atom.xml" title="章军的博客" type="application/atom+xml">
  
  
    <link rel="icon" href="/favicon.png">
  
  
    <link href="//fonts.googleapis.com/css?family=Source+Code+Pro" rel="stylesheet" type="text/css">
  
  <link rel="stylesheet" href="/css/style.css">
</head>
</html>
<body>
  <div id="container">
    <div id="wrap">
      <header id="header">
  <div id="banner"></div>
  <div id="header-outer" class="outer">
    <div id="header-title" class="inner">
      <h1 id="logo-wrap">
        <a href="/" id="logo">章军的博客</a>
      </h1>
      
    </div>
    <div id="header-inner" class="inner">
      <nav id="main-nav">
        <a id="main-nav-toggle" class="nav-icon"></a>
        
          <a class="main-nav-link" href="/">Home</a>
        
          <a class="main-nav-link" href="/archives">Archives</a>
        
      </nav>
      <nav id="sub-nav">
        
          <a id="nav-rss-link" class="nav-icon" href="/atom.xml" title="RSS Feed"></a>
        
        <a id="nav-search-btn" class="nav-icon" title="Search"></a>
      </nav>
      <div id="search-form-wrap">
        <form action="//google.com/search" method="get" accept-charset="UTF-8" class="search-form"><input type="search" name="q" class="search-form-input" placeholder="Search"><button type="submit" class="search-form-submit">&#xF002;</button><input type="hidden" name="sitesearch" value="http://octopuscloud.top"></form>
      </div>
    </div>
  </div>
</header>
      <div class="outer">
        <section id="main"><article id="post-linux-platform-bus-总线分析" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-meta">
    <a href="/2019/10/19/linux-platform-bus-总线分析/" class="article-date">
  <time datetime="2019-10-19T07:25:17.000Z" itemprop="datePublished">2019-10-19</time>
</a>
    
  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 class="article-title" itemprop="name">
      linux platform bus 总线分析
    </h1>
  

      </header>
    
    <div class="article-entry" itemprop="articleBody">
      
        <h1 id="1-Linux-平台总线的简介-platform-bus"><a href="#1-Linux-平台总线的简介-platform-bus" class="headerlink" title="1. Linux 平台总线的简介 (platform bus)"></a>1. Linux 平台总线的简介 (platform bus)</h1><pre><code>    关于平台总线我把 linux kernel 下的文档翻译了一遍 ，英文原版地址为 https://github.com/torvalds/linux/blob/master/
Documentation/driver-api/driver-model/platform.rst , 翻译后的地址为 https://github.com/singledo/SortCode/blob/master/
translater/platform.md 。哈哈 ，有啥看的别扭的 ，对照英文文档看就好了 。

    对于不愿看同学 ，我简单介绍下平台总线是个什么东西 。

　　平台总线是 Linux 一种类似于 I₂C 总线的虚拟设备 。虚拟设备的由来是因为平台设备并没有实际的硬件控制器与平台总线相对应 ，
平台总线上挂载平台设备 (platform device)  和平台驱动 (platform driver) 。平台设备一般是有实际存在的硬件与之对应的 ；平台
驱动是控制平台设备的　。
</code></pre><h2 id="2-平台总线的初始化过程"><a href="#2-平台总线的初始化过程" class="headerlink" title="2. 平台总线的初始化过程"></a>2. 平台总线的初始化过程</h2><pre><code>    平台总线能分为三个部分 ，平台总线 BUS 的初始化 ，平台总线设备的初始化 ，平台总线驱动的初始化 。平台总线 BUS 的初始化在内核
初始化的过程中完成 ，平台总线设备和驱动的初始化在驱动挂载的时候完成 。
</code></pre><h3 id="2-1-平台总线-BUS-的初始化过程"><a href="#2-1-平台总线-BUS-的初始化过程" class="headerlink" title="2.1 平台总线 BUS 的初始化过程"></a>2.1 平台总线 BUS 的初始化过程</h3><pre><code>BUS 的初始化在将一些全局的变量准备好 ，以方便后面驱动的添加 。我们先对整个初始化函数有个预览 ，后面会来详细的分析 。

int __init platform_bus_init(void)
{
  int error;
  early_platform_cleanup();

  error = device_register(&amp;platform_bus);
  if (error) {
    put_device(&amp;platform_bus);
    return error;
  }
  error =  bus_register(&amp;platform_bus_type);
  if (error)
    device_unregister(&amp;platform_bus);
  of_platform_register_reconfig_notifier();
  return error;
}

- early_platform_cleanup ()
  准备初始化的前期动作 ，将 early_platform_device_list 链表中的所有的 dev.devres_head 设备为空链 ，并将链表的 head 置空 。

- device_register (&amp;platform_bus)
  此步骤会现将设备结构体的各项填上正确的值或者函数 ，然后用用正确的属性来创建设备对应的链接或者是文件 。并将设备加到对应
  的链表的末尾 。

  static const struct dev_pm_ops platform_dev_pm_ops = {
    .runtime_suspend = pm_generic_runtime_suspend,
    .runtime_resume = pm_generic_runtime_resume,
    USE_PLATFORM_PM_SLEEP_OPS
  };

  struct bus_type platform_bus_type = {
    .name          = &quot;platform&quot;,
    .dev_groups    = platform_dev_groups,
    .match         = platform_match,
    .uevent        = platform_uevent,
    .dma_configure = platform_dma_configure,
    .pm            = &amp;platform_dev_pm_ops,
  };

- 平台总线的 BUS 初始化
</code></pre><h2 id="2-2-平台总线设备的初始化"><a href="#2-2-平台总线设备的初始化" class="headerlink" title="2.2 平台总线设备的初始化"></a>2.2 平台总线设备的初始化</h2><h2 id="2-3-平台总驱动的初始化"><a href="#2-3-平台总驱动的初始化" class="headerlink" title="2.3 平台总驱动的初始化"></a>2.3 平台总驱动的初始化</h2><hr>
<ol>
<li><a href="https://www.cnblogs.com/biglucky/p/4057481.html" target="_blank" rel="noopener">https://www.cnblogs.com/biglucky/p/4057481.html</a></li>
<li><a href="https://blog.csdn.net/cc289123557/article/details/51782449" target="_blank" rel="noopener">https://blog.csdn.net/cc289123557/article/details/51782449</a></li>
</ol>

      
    </div>
    <footer class="article-footer">
      <a data-url="http://octopuscloud.top/2019/10/19/linux-platform-bus-总线分析/" data-id="ck471vq0z001032fz5uvjt5ti" class="article-share-link">Share</a>
      
      
  <ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/linux-driver/">linux driver</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/platform-bus/">platform bus</a></li></ul>

    </footer>
  </div>
  
    
<nav id="article-nav">
  
    <a href="/2019/11/02/SegmentationFault-Debug/" id="article-nav-newer" class="article-nav-link-wrap">
      <strong class="article-nav-caption">Newer</strong>
      <div class="article-nav-title">
        
          (no title)
        
      </div>
    </a>
  
  
    <a href="/2019/10/17/Linux-Kernel-启动分析/" id="article-nav-older" class="article-nav-link-wrap">
      <strong class="article-nav-caption">Older</strong>
      <div class="article-nav-title">Linux Kernel 启动分析</div>
    </a>
  
</nav>

  
</article>

</section>
        
          <aside id="sidebar">
  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Categories</h3>
    <div class="widget">
      <ul class="category-list"><li class="category-list-item"><a class="category-list-link" href="/categories/RFC/">RFC</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/RFC-protocol/">RFC protocol</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/ReadNote/">ReadNote</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/linux/">linux</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/protocols/">protocols</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/tools/">tools</a></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Tags</h3>
    <div class="widget">
      <ul class="tag-list"><li class="tag-list-item"><a class="tag-list-link" href="/tags/C/">C</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Data-Struct/">Data Struct</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Ethernet-II/">Ethernet II</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Frame-Format/">Frame Format</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/I2C/">I2C</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/IPv6/">IPv6</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Neighbour-Discover-Protocol/">Neighbour Discover Protocol</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/RFC/">RFC</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/SNMP/">SNMP</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/arthmetic/">arthmetic</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/cgdb/">cgdb</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/chapter-15/">chapter 15</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/data-struct/">data struct</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/deb/">deb</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/defalt-path-for-so-file/">defalt path for so file</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/editer/">editer</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/file-system/">file system</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/gdb-debug/">gdb debug</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/hash/">hash</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/linux/">linux</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/linux-driver/">linux driver</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/platform-bus/">platform bus</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/pointer-array/">pointer, array</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/pseudocode/">pseudocode</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/rb-tree/">rb tree</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/sort/">sort</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/ssh-key/">ssh key</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/symbol/">symbol</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/tool/">tool</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/tools/">tools</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/图/">图</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/通信协议/">通信协议</a></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Tag Cloud</h3>
    <div class="widget tagcloud">
      <a href="/tags/C/" style="font-size: 10px;">C</a> <a href="/tags/Data-Struct/" style="font-size: 10px;">Data Struct</a> <a href="/tags/Ethernet-II/" style="font-size: 10px;">Ethernet II</a> <a href="/tags/Frame-Format/" style="font-size: 10px;">Frame Format</a> <a href="/tags/I2C/" style="font-size: 10px;">I2C</a> <a href="/tags/IPv6/" style="font-size: 15px;">IPv6</a> <a href="/tags/Neighbour-Discover-Protocol/" style="font-size: 10px;">Neighbour Discover Protocol</a> <a href="/tags/RFC/" style="font-size: 10px;">RFC</a> <a href="/tags/SNMP/" style="font-size: 10px;">SNMP</a> <a href="/tags/arthmetic/" style="font-size: 10px;">arthmetic</a> <a href="/tags/cgdb/" style="font-size: 10px;">cgdb</a> <a href="/tags/chapter-15/" style="font-size: 10px;">chapter 15</a> <a href="/tags/data-struct/" style="font-size: 15px;">data struct</a> <a href="/tags/deb/" style="font-size: 10px;">deb</a> <a href="/tags/defalt-path-for-so-file/" style="font-size: 10px;">defalt path for so file</a> <a href="/tags/editer/" style="font-size: 10px;">editer</a> <a href="/tags/file-system/" style="font-size: 10px;">file system</a> <a href="/tags/gdb-debug/" style="font-size: 10px;">gdb debug</a> <a href="/tags/hash/" style="font-size: 10px;">hash</a> <a href="/tags/linux/" style="font-size: 20px;">linux</a> <a href="/tags/linux-driver/" style="font-size: 10px;">linux driver</a> <a href="/tags/platform-bus/" style="font-size: 10px;">platform bus</a> <a href="/tags/pointer-array/" style="font-size: 10px;">pointer, array</a> <a href="/tags/pseudocode/" style="font-size: 10px;">pseudocode</a> <a href="/tags/rb-tree/" style="font-size: 10px;">rb tree</a> <a href="/tags/sort/" style="font-size: 20px;">sort</a> <a href="/tags/ssh-key/" style="font-size: 10px;">ssh key</a> <a href="/tags/symbol/" style="font-size: 10px;">symbol</a> <a href="/tags/tool/" style="font-size: 10px;">tool</a> <a href="/tags/tools/" style="font-size: 10px;">tools</a> <a href="/tags/图/" style="font-size: 10px;">图</a> <a href="/tags/通信协议/" style="font-size: 10px;">通信协议</a>
    </div>
  </div>

  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Archives</h3>
    <div class="widget">
      <ul class="archive-list"><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/12/">December 2019</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/11/">November 2019</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/10/">October 2019</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/09/">September 2019</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/08/">August 2019</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/07/">July 2019</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/06/">June 2019</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/05/">May 2019</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/04/">April 2019</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/03/">March 2019</a></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Recent Posts</h3>
    <div class="widget">
      <ul>
        
          <li>
            <a href="/2019/12/15/TMUX-使用/">TMUX-使用</a>
          </li>
        
          <li>
            <a href="/2019/11/02/linux-platform-bus-总线分析/platform/">(no title)</a>
          </li>
        
          <li>
            <a href="/2019/11/02/十二章-二叉搜索树/">算法导论-第十二章 二叉查找树</a>
          </li>
        
          <li>
            <a href="/2019/11/02/SegmentationFault-Debug/">(no title)</a>
          </li>
        
          <li>
            <a href="/2019/10/19/linux-platform-bus-总线分析/">linux platform bus 总线分析</a>
          </li>
        
      </ul>
    </div>
  </div>

  
</aside>
        
      </div>
      <footer id="footer">
  
  <div class="outer">
    <div id="footer-info" class="inner">
      &copy; 2019 zhangjun<br>
      Powered by <a href="http://hexo.io/" target="_blank">Hexo</a>
    </div>
  </div>
</footer>
    </div>
    <nav id="mobile-nav">
  
    <a href="/" class="mobile-nav-link">Home</a>
  
    <a href="/archives" class="mobile-nav-link">Archives</a>
  
</nav>
    

<script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>


  <link rel="stylesheet" href="/fancybox/jquery.fancybox.css">
  <script src="/fancybox/jquery.fancybox.pack.js"></script>


<script src="/js/script.js"></script>



  </div>
</body>
</html>